home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6134 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: ix.netcom.com!netnews
  2. From: judgemi@ix.netcom.com(Michael Judge )
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Scan a file. Urgent!!!!!!
  5. Date: 11 Feb 1996 23:35:51 GMT
  6. Organization: Netcom
  7. Message-ID: <4flugn$hj6@ixnews3.ix.netcom.com>
  8. References: <1996Feb11.120142.113766@kuhub.cc.ukans.edu>
  9. NNTP-Posting-Host: ix-bst-ma1-19.ix.netcom.com
  10. X-NETCOM-Date: Sun Feb 11  3:35:51 PM PST 1996
  11.  
  12. In <1996Feb11.120142.113766@kuhub.cc.ukans.edu> moxu@kuhub.cc.ukans.edu
  13. writes: 
  14. >
  15. >    A data file has integers, a few characters. I want to read the
  16. content
  17. >out and assign integer values in the file into an array. I use
  18. "fscanf". The
  19. >things is when I use "fscanf(datafile,"%d",&digit)", the execution
  20. halted when
  21. >a character was encounted, probably because this sentence returns
  22. "NULL". So, I
  23. >can't read through the file and assign all the data into the array.
  24. >    Urgent! The project is due Wednesday and now I haven't even set
  25. up the array
  26. >yet!
  27. >    Any hint will be highly appreciated!
  28. >    Thanks a lot!
  29.  
  30. off the top of my head i think the problem here is that you are trying
  31. to scan an integer and since it doesnt find one it leaves the file
  32. pointer right where it is. If you want to read in an integer and maybe
  33. there is a character then you should read a character at a time and
  34. check if its an integer or not if it is proceed to check the next
  35. character and if its >='0' and <='9' then multiply first by 10 and add
  36. the second until you dont find a number. then go to the next number
  37. ect. maybe there is a more slick way to do this but this is just a
  38. quick answer.
  39.  
  40.  
  41.